package com.tydic.trans.controller;

import com.tydic.trans.beans.Account;
import com.tydic.trans.beans.Stock;
import com.tydic.trans.exceptions.StockException;
import com.tydic.trans.service.impl.StockServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/trans")
public class StockController {
    @Autowired
    private StockServiceImpl stockService;

    @GetMapping("testBuyStock")
    public void testBuyStock() throws StockException {
        System.out.println("service:" + stockService.getClass().getName());
        stockService.buyStock("张三", 1000, "zs", 500);
        System.out.println("买股票的操作");
    }

    @GetMapping("testOpenAccount")
    public void testOpenAccount() {
        Account account = new Account();
        account.setAname("张三");
        account.setBalance(10000);
        stockService.openAccount(account);
    }

    @GetMapping("testFindAccount")
    public void testFindAccount() {
        Account account = stockService.findAccount("张三");
        System.out.println("account:" + account);
    }

    @GetMapping("testOpenStock")
    public void testOpenStock() {
        Stock stock = new Stock();
        stock.setSname("zs");
        stock.setCount(0);
        stockService.openStock(stock);
    }

    @GetMapping("testFindStock")
    public void testFindStock() {
        Stock stock = stockService.findStock("zs");
        System.out.println("stock:" + stock);
    }
}
